﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Stone.DataContracts;
using Stone.Library.Common;

namespace CourseArraging.Frm.xygl
{
    public partial class FrmStuZmCondi : Form
    {
        public enum FrmMode
        {
            FRM_STU_KCB,
            FRM_STU_ZMAP
        }
        YhxxService.YhxxServiceClient yhxxdao = new YhxxService.YhxxServiceClient();
        private FrmMode curFrmMode;
        public delegate void FilterEventHandler(List<StuArrangeEntity> sList);
        public event FilterEventHandler FilterEvent;
        public delegate void FilterDTEventHandler(DataTable dt);
        public event FilterDTEventHandler FilterDTEvent;

        private static FrmStuZmCondi Instance;
        private FrmStuZmCondi()
        {
            InitializeComponent();
        }

        private FrmStuZmCondi(FrmMode frmMode)
            : this()
        {
            this.curFrmMode = frmMode;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="frmMode">"FRM_STU_KCB","FRM_STU_ZMAP"</param>
        /// <returns></returns>
        public static FrmStuZmCondi getInstance(FrmMode frmMode)
        {
            if (Instance == null || Instance.IsDisposed)
            {
                Instance = new FrmStuZmCondi(frmMode);
            }
            return Instance;
        }

        private void tsb_ok_Click(object sender, EventArgs e)
        {
            if (txtKhname.Text == string.Empty)
            {
                MessageBox.Show("请填写客户简拼");
                return;
            }
            FilterManage();
        }

        private void FilterManage()
        {
            List<StuArrangeEntity> stuList=new List<StuArrangeEntity>();
            if (curFrmMode == FrmMode.FRM_STU_ZMAP)
            {
                StuEntity stuEntity = new StuEntity();
                stuEntity.user_spell = String2pyHelper.GetPYStr(txtKhname.Text);
                stuList = yhxxdao.GetStuArrlist4Zmap(stuEntity).ToList<StuArrangeEntity>();      
                if (FilterEvent != null)
                FilterEvent(stuList);
            }
            else if (curFrmMode == FrmMode.FRM_STU_KCB)
            {
                StuEntity stuEntity = new StuEntity();
                stuEntity.user_spell = String2pyHelper.GetPYStr(txtKhname.Text);
                DataTable dt = yhxxdao.GetStu8Entity(stuEntity);
                if (FilterDTEvent != null)
                    FilterDTEvent(dt);
            }

            this.Close();
        }

        private void tsb_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tsb_ok_Click(null, null);
        }
    }
}
